Surplus_Up (2DU) 7 лет назад
Родитель
Сommit
0c7a969bd1
2 измененных файлов с 49 добавлено и 33 удалено
  1. 44 30
      route/now_update.py
  2. 5 3
      route/restart.py

+ 44 - 30
route/now_update.py

@@ -3,41 +3,55 @@ from .tool.func import *
 def now_update_2(conn):
     curs = conn.cursor()
 
-    if admin_check(None, 'update') != 1:
-       return re_error('/error/3')
+    if admin_check() != 1:
+        return re_error('/error/3')
 
-    curs.execute('select data from other where name = "update"')
-    up_data = curs.fetchall()
-    if up_data:
-        up_data = up_data[0][0]
-    else:
-        up_data = 'stable'
+    if flask.request.method == 'POST':
+        admin_check(None, 'update')
 
-    if platform.system() == 'Linux':
-        print('Update')
+        curs.execute('select data from other where name = "update"')
+        up_data = curs.fetchall()
+        if up_data:
+            up_data = up_data[0][0]
+        else:
+            up_data = 'stable'
 
-        os.system('git remote rm origin')
-        os.system('git remote add origin https://github.com/2DU/opennamu.git')
-        ok = os.system('git fetch origin ' + up_data)
-        ok = os.system('git reset --hard origin/' + up_data)
-        if ok == 0:
-            return redirect('/restart')
-    else:
-        if platform.system() == 'Windows':
+        if platform.system() == 'Linux':
             print('Update')
 
-            urllib.request.urlretrieve('https://github.com/2DU/opennamu/archive/' + up_data + '.zip', 'update.zip')
-            zipfile.ZipFile('update.zip').extractall('')
-            ok = os.system('xcopy /y /r opennamu-' + up_data + ' .')
+            os.system('git remote rm origin')
+            os.system('git remote add origin https://github.com/2DU/opennamu.git')
+            ok = os.system('git fetch origin ' + up_data)
+            ok = os.system('git reset --hard origin/' + up_data)
             if ok == 0:
-                print('Remove')
-                os.system('rd /s /q opennamu-' + up_data)
-                os.system('del update.zip')
-
                 return redirect('/restart')
+        else:
+            if platform.system() == 'Windows':
+                print('Update')
+
+                urllib.request.urlretrieve('https://github.com/2DU/opennamu/archive/' + up_data + '.zip', 'update.zip')
+                zipfile.ZipFile('update.zip').extractall('')
+                ok = os.system('xcopy /y /r opennamu-' + up_data + ' .')
+                if ok == 0:
+                    print('Remove')
+                    os.system('rd /s /q opennamu-' + up_data)
+                    os.system('del update.zip')
+
+                    return redirect('/restart')
+
+        return easy_minify(flask.render_template(skin_check(), 
+            imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
+            data = load_lang("update_error") + ' <a href="https://github.com/2DU/opennamu">(Github)</a>',
+            menu = [['manager/1', load_lang('return')]]
+        ))
+    else:
+        return easy_minify(flask.render_template(skin_check(), 
+            imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
+            data =  '''
+                    <form method="post">
+                        <button type="submit">''' + load_lang('update') + '''</button>
+                    </form>
+                    ''',
+            menu = [['manager', load_lang('return')]]
+        ))
 
-    return easy_minify(flask.render_template(skin_check(), 
-        imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
-        data = load_lang("update_error") + ' <a href="https://github.com/2DU/opennamu">(Github)</a>',
-        menu = [['manager/1', load_lang('return')]]
-    ))

+ 5 - 3
route/restart.py

@@ -3,14 +3,16 @@ from .tool.func import *
 def restart_2(conn):
     curs = conn.cursor()
 
-    if admin_check(None, 'restart') != 1:
+    if admin_check() != 1:
         return re_error('/error/3')
 
     if flask.request.method == 'POST':
-        os.execl(sys.executable, sys.executable, *sys.argv)
-    else:
+        admin_check(None, 'restart')
+
         print('Restart')
 
+        os.execl(sys.executable, sys.executable, *sys.argv)
+    else:
         return easy_minify(flask.render_template(skin_check(), 
             imp = [load_lang('wiki_restart'), wiki_set(), custom(), other2([0, 0])],
             data =  '''