Example #1
0
    def resend_shh_key(self, request, queryset):
        form = None
        if 'apply' in request.POST:
            form = self.SshForm(request.POST)
            if form.is_valid():
                try:
                    if not path.isfile(settings.PROJECT_ROOT + "/keys/id_rsa"):
                        system("ssh-keygen -t rsa -f " + settings.PROJECT_ROOT + "/keys/id_rsa -N ''")
                    sondas_updated = 0
                    user = request.POST["user"]
                    password = request.POST["passwd"]

                    for tasklog in SondaTasksLog.objects.all():
                        if (tasklog.sonda.ssh is False or request.POST.get("force", '') != '') and tasklog.task.name == "ssh_key":
                            last_timestamp = max([i.timestamp for i in SondaTaskStatus.objects.filter(tasklog=tasklog)])
                            taskstatus = SondaTaskStatus.objects.get(timestamp=last_timestamp, tasklog=tasklog)
                            if taskstatus.status > 0:
                                ssh_key_send_task.apply_async(
                                    (tasklog.sonda.pk, user, password, tasklog.pk), serializer="json")
                                sondas_updated += 1
                except:
                    fails = "\n"
                    for fail in sys.exc_info()[0:5]:
                        fails = fails + str(fail) + "\n"
                    messages.error(request, 'Error :' + fails)
                    return HttpResponseRedirect(request.get_full_path())

                messages.info(request, str(sondas_updated) + ' sondas have been pushed to the task queue')
                return HttpResponseRedirect(request.get_full_path())

        if not form:
            form = self.SshForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
        return render_to_response('confssh.html',
                                  {"form": form, "action": "resend_shh_key"},
                                  context_instance=RequestContext(request))
Example #2
0
    def ssh_key(self, request, queryset):
        print(request.POST)
        form = None
        if 'apply' in request.POST:
            form = self.SshForm(request.POST)
            if form.is_valid():

                if not path.isfile(settings.PROJECT_ROOT + "/keys/id_rsa"):
                    system("ssh-keygen -t rsa -f " + settings.PROJECT_ROOT + "/keys/id_rsa -N ''")
                sondas_updated = 0
                user = request.POST["user"]
                password = request.POST["passwd"]

                for sonda in queryset:
                    if sonda.ssh is False or request.POST.get("force", '') != '':
                        ssh_key_send_task.apply_async((sonda.pk, user, password, None), serializer="json")
                        #ssh_key_send_task(sonda.pk, user, password, None)
                        sondas_updated += 1

                messages.info(request, str(sondas_updated) + ' sondas have been pushed to the task queue')
                return HttpResponseRedirect(request.get_full_path())

        if not form:
            form = self.SshForm(initial={'_selected_action': request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
        return render_to_response('confssh.html',
                                  {"form": form, "action": "ssh_key"},
                                  context_instance=RequestContext(request))