Commit 22433a00 authored by Jondy Zhao's avatar Jondy Zhao

Fix netreport trial bugs

parent e37ab642
...@@ -141,11 +141,11 @@ class NetDriveUsageReporter(object): ...@@ -141,11 +141,11 @@ class NetDriveUsageReporter(object):
def insertUsageReport(self, monitor, start, duration): def insertUsageReport(self, monitor, start, duration):
q = self._db.execute q = self._db.execute
for r in monitor.usageReport(): for r in eval(monitor.netdrive_usage()):
q( "INSERT INTO net_drive_usage " q( "INSERT INTO net_drive_usage "
"(config_id, domain_user, drive_letter, remote_folder, " "(config_id, domain_user, drive_letter, remote_folder, "
" start, duration, usage_bytes )" " start, duration, usage_bytes )"
" VALUES (?, ?, ?, ?, ?, ?)", " VALUES (?, ?, ?, ?, ?, ?, ?)",
(self._config_id, r[0], r[1], r[2], start, duration, r[4] - r[3])) (self._config_id, r[0], r[1], r[2], start, duration, r[4] - r[3]))
def sendAllReport(self): def sendAllReport(self):
......
...@@ -131,7 +131,7 @@ netuse_user_info(PyObject *self, PyObject *args) ...@@ -131,7 +131,7 @@ netuse_user_info(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
static int static int
wnet_enumerate_netdrive(LPNETRESOURCE lpnr) wnet_enumerate_netdrive(LPNETRESOURCE lpnr)
{ {
DWORD dwResult, dwResultEnum; DWORD dwResult, dwResultEnum;
...@@ -140,9 +140,9 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr) ...@@ -140,9 +140,9 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr)
DWORD cEntries = -1; // enumerate all possible entries DWORD cEntries = -1; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i; DWORD i;
dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_DISK, RESOURCETYPE_DISK,
0, 0,
lpnr, // NULL first time the function is called lpnr, // NULL first time the function is called
&hEnum); // handle to the resource &hEnum); // handle to the resource
...@@ -161,7 +161,7 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr) ...@@ -161,7 +161,7 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr)
dwResultEnum = WNetEnumResource(hEnum, // resource handle dwResultEnum = WNetEnumResource(hEnum, // resource handle
&cEntries, // defined locally as -1 &cEntries, // defined locally as -1
lpnrLocal, // LPNETRESOURCE lpnrLocal, // LPNETRESOURCE
&cbBuffer); &cbBuffer);
if (dwResultEnum == NO_ERROR) { if (dwResultEnum == NO_ERROR) {
for (i = 0; i < cEntries; i++) { for (i = 0; i < cEntries; i++) {
printf("NETRESOURCE[%ld] Usage: 0x%ld = ", i, lpnrLocal[i].dwUsage); printf("NETRESOURCE[%ld] Usage: 0x%ld = ", i, lpnrLocal[i].dwUsage);
...@@ -199,7 +199,7 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr) ...@@ -199,7 +199,7 @@ wnet_enumerate_netdrive(LPNETRESOURCE lpnr)
return TRUE; return TRUE;
} }
static int static int
reg_enumerate_netdrive(void) reg_enumerate_netdrive(void)
{ {
/* LsaEnumerateLogonSessions -> LogonId */ /* LsaEnumerateLogonSessions -> LogonId */
...@@ -228,7 +228,7 @@ netuse_list_drive(PyObject *self, PyObject *args) ...@@ -228,7 +228,7 @@ netuse_list_drive(PyObject *self, PyObject *args)
char szRemoteName[MAX_PATH]; char szRemoteName[MAX_PATH];
DWORD dwResult; DWORD dwResult;
DWORD cchBuff = MAX_PATH; DWORD cchBuff = MAX_PATH;
char szUserName[MAX_PATH]; char szUserName[MAX_PATH] = {0};
if (! PyArg_ParseTuple(args, "|s", &servername)) { if (! PyArg_ParseTuple(args, "|s", &servername)) {
return NULL; return NULL;
...@@ -243,13 +243,15 @@ netuse_list_drive(PyObject *self, PyObject *args) ...@@ -243,13 +243,15 @@ netuse_list_drive(PyObject *self, PyObject *args)
drivename[0] = chdrive; drivename[0] = chdrive;
dwResult = WNetGetConnection(drivename, dwResult = WNetGetConnection(drivename,
szRemoteName, szRemoteName,
&cchBuff &cchBuff
); );
if (dwResult == NO_ERROR) { if (dwResult == NO_ERROR) {
dwResult = WNetGetUser("z:", dwResult = WNetGetUser(drivename,
(LPSTR) szUserName, (LPSTR) szUserName,
&cchBuff); &cchBuff);
if (dwResult != NO_ERROR)
snprintf(szUserName, MAX_PATH, "%s", "Unknown User");
pobj = Py_BuildValue("ssss", pobj = Py_BuildValue("ssss",
drivename, drivename,
szRemoteName, szRemoteName,
...@@ -299,7 +301,7 @@ connect_net_drive(char *remote, char *drive) ...@@ -299,7 +301,7 @@ connect_net_drive(char *remote, char *drive)
dwFlags = CONNECT_REDIRECT; dwFlags = CONNECT_REDIRECT;
dwRetVal = WNetAddConnection2(&nr, password, user, dwFlags); dwRetVal = WNetAddConnection2(&nr, password, user, dwFlags);
if (dwRetVal == NO_ERROR) if (dwRetVal == NO_ERROR)
return 0; return 0;
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"WNetAddConnection2 failed with error: %lu\n", "WNetAddConnection2 failed with error: %lu\n",
...@@ -327,7 +329,7 @@ netuse_remove_drive(PyObject *self, PyObject *args) ...@@ -327,7 +329,7 @@ netuse_remove_drive(PyObject *self, PyObject *args)
dwRetVal = WNetCancelConnection2(drive, 0, force); dwRetVal = WNetCancelConnection2(drive, 0, force);
if (dwRetVal == NO_ERROR) if (dwRetVal == NO_ERROR)
Py_RETURN_NONE; Py_RETURN_NONE;
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"WNetCancelConnection2 failed with error: %lu\n", "WNetCancelConnection2 failed with error: %lu\n",
dwRetVal dwRetVal
...@@ -670,7 +672,7 @@ static PyMethodDef NetUseMethods[] = { ...@@ -670,7 +672,7 @@ static PyMethodDef NetUseMethods[] = {
"When drive is an empty string, the system will automatically\n" "When drive is an empty string, the system will automatically\n"
"assigns network drive letters, letters are assigned beginning\n" "assigns network drive letters, letters are assigned beginning\n"
"with Z:, then Y:, and ending with C:\n." "with Z:, then Y:, and ending with C:\n."
"For examples," "For examples,\n"
" mapNetDrive(r'\\\\server\\data')\n" " mapNetDrive(r'\\\\server\\data')\n"
" mapNetDrive(r'\\\\server\\data', 'T:')\n" " mapNetDrive(r'\\\\server\\data', 'T:')\n"
" mapNetDrive(r'\\\\server\\data', 'T:', r'\\\\server\\jack', 'abc')\n" " mapNetDrive(r'\\\\server\\data', 'T:', r'\\\\server\\jack', 'abc')\n"
...@@ -711,7 +713,7 @@ static PyMethodDef NetUseMethods[] = { ...@@ -711,7 +713,7 @@ static PyMethodDef NetUseMethods[] = {
( (
"userInfo()\n\n" "userInfo()\n\n"
"Get the logon user information, return a tuple:\n" "Get the logon user information, return a tuple:\n"
"(server, domain, user).\n" " (server, domain, user).\n"
) )
}, },
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
......
...@@ -148,7 +148,7 @@ function configure_section_re6stnet() ...@@ -148,7 +148,7 @@ function configure_section_re6stnet()
csih_inform "checking miniupnpc ..." csih_inform "checking miniupnpc ..."
if [[ ! -d /opt/miniupnpc ]] ; then if [[ ! -d /opt/miniupnpc ]] ; then
_filename=/opt/downloads/miniupnpc.tar.gz _filename=/opt/downloads/miniupnpc.tar.gz
[[ -r ${_filename} ]] || [[ -r ${_filename} ]] ||
wget -c http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.8.tar.gz -O ${_filename} || wget -c http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.8.tar.gz -O ${_filename} ||
csih_error "No package found: ${_filename}" csih_error "No package found: ${_filename}"
csih_inform "installing miniupnpc ..." csih_inform "installing miniupnpc ..."
...@@ -166,7 +166,7 @@ function configure_section_re6stnet() ...@@ -166,7 +166,7 @@ function configure_section_re6stnet()
csih_inform "checking pyOpenSSL ..." csih_inform "checking pyOpenSSL ..."
if [[ ! -d /opt/pyOpenSSL ]] ; then if [[ ! -d /opt/pyOpenSSL ]] ; then
_filename=/opt/downloads/pyOpenSSL.tar.gz _filename=/opt/downloads/pyOpenSSL.tar.gz
[[ -r ${_filename} ]] || [[ -r ${_filename} ]] ||
wget -c --no-check-certificate https://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz#md5=767bca18a71178ca353dff9e10941929 -O ${_filename} || wget -c --no-check-certificate https://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz#md5=767bca18a71178ca353dff9e10941929 -O ${_filename} ||
csih_error "No package found: ${_filename}" csih_error "No package found: ${_filename}"
csih_inform "installing pyOpenSSL ..." csih_inform "installing pyOpenSSL ..."
...@@ -218,7 +218,7 @@ function configure_section_re6stnet() ...@@ -218,7 +218,7 @@ function configure_section_re6stnet()
csih_inform " ovpnlog" csih_inform " ovpnlog"
csih_inform " main-interface ${slapos_ifname}" csih_inform " main-interface ${slapos_ifname}"
csih_inform " interface ${slapos_ifname}" csih_inform " interface ${slapos_ifname}"
echo -e "# $subnet\ntable 0\nlog ${_log_path}\novpnlog" \ echo -e "# $subnet\ntable 0\novpnlog" \
"\nmain-interface ${slapos_ifname}\ninterface ${slapos_ifname}" \ "\nmain-interface ${slapos_ifname}\ninterface ${slapos_ifname}" \
>> ${re6stnet_configure_file} >> ${re6stnet_configure_file}
fi fi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment